﻿<%@ WebHandler Language="C#" Class="UpdateUser" %>

using System;
using System.Web;
using System.Xml;
using System.Web.SessionState;
using Nullables;
using PermissionBase.Core.Service;
using PermissionBase.Core.DTO;

public class UpdateUser : IHttpHandler, IReadOnlySessionState
{
    private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(UpdateUser));

    public void ProcessRequest(HttpContext context)
    {
        context.Response.Cache.SetCacheability(HttpCacheability.NoCache);

        string sSucceed = "1";
        try
        {
            //判断访问权限。
            PermissionUtil.CheckSecurity("UserMgr", "rights_edit");

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(context.Request.InputStream);

            UserDTO dto = new UserDTO();
            dto.m_dms_emp_base_id = Convert.ToDecimal(xmlDoc.SelectSingleNode("User/Id").InnerText);
            dto.m_emp_code = xmlDoc.SelectSingleNode("User/LoginId").InnerText;
            dto.m_emp_name = xmlDoc.SelectSingleNode("User/Name").InnerText;
            string sex = xmlDoc.SelectSingleNode("User/Sex").InnerText;
            dto.m_emp_sex = (sex == "-1" ? null : Convert.ToString(new NullableInt32(int.Parse(sex))));

            string birthday = xmlDoc.SelectSingleNode("User/Birthday").InnerText;
            dto.m_emp_birthday = (birthday.Length > 0 ? NullableDateTime.Parse(birthday) : null);

            UserSrv.UpdateUser(dto);
        }
        catch (Exception ex)
        {
            sSucceed = "-1";
            log.Error(null, ex);
        }
        finally
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write(sSucceed);
            context.Response.End();
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}